﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.UpgradesUI {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import flash.utils.*;
    import org.aswing.*;
    import Classes.*;
    import org.aswing.geom.*;
    import Display.aswingui.*;
    import org.aswing.colorchooser.*;

    public class BusinessUpgradesInfoBox extends JPanel {

        public static const BOX_HEIGHT:Number = 275;
        public static const CELL_WIDTH:Number = 185;
        public static const CELL_HEIGHT:Number = 250;
        public static const CELL_BUFFER:Number = 20;
        public static const PIC_HEIGHT:Number = 80;

        protected var m_item:Item;
        protected var m_stats:Dictionary;
        protected var m_bgAsset:DisplayObject;
        protected var m_cellContainer:JPanel;
        protected var m_levelStarContainer:JPanel;
        protected var m_pictureContainer:JPanel;
        protected var m_statsInnerContainer:JPanel;
        protected var m_statsOuterContainer:JPanel;
        protected var m_picture:DisplayObject;
        protected var m_pictureLoader:Loader;

        public function BusinessUpgradesInfoBox(_arg1:Object, _arg2:String){
            this.m_bgAsset = (new (_arg1)() as DisplayObject);
            this.m_item = Global.gameSettings.getItemByName(_arg2);
            if (this.m_item){
                this.m_pictureLoader = LoadingManager.load(Global.getAssetURL(this.m_item.iconRelative), this.onPicLoad, LoadingManager.PRIORITY_HIGH);
            };
            super(new VerticalLayout(VerticalLayout.CENTER));
            this.buildCell();
        }
        protected function buildCell():void{
            var _local1:DisplayObject;
            var _local2:Sprite;
            this.m_cellContainer = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            this.m_levelStarContainer = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER, 5);
            this.m_pictureContainer = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            this.m_statsInnerContainer = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.LEFT);
            this.m_statsOuterContainer = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.LEFT);
            this.buildBackground();
            this.makeLevelPanel();
            this.makePicturePanel();
            this.makeStatsPanel();
            this.append(this.m_cellContainer);
            this.m_cellContainer.append(ASwingHelper.verticalStrut(5));
            this.m_cellContainer.append(this.m_levelStarContainer);
            this.m_cellContainer.append(ASwingHelper.verticalStrut(18));
            this.m_cellContainer.append(this.m_pictureContainer);
            this.m_cellContainer.append(this.m_statsOuterContainer);
            if (this.m_bgAsset){
                if (this.m_bgAsset.name.indexOf("current") != -1){
                    _local1 = (new (UpgradesCommonAssets.bizupsAssetDict["checkMark"])() as DisplayObject);
                    _local1.x = (((CELL_WIDTH - (CELL_BUFFER / 2)) - _local1.width) + 5);
                    _local1.y = (CELL_HEIGHT - _local1.height);
                    _local2 = new Sprite();
                    _local2.addChild(_local1);
                    this.addChild(_local2);
                };
            };
            ASwingHelper.prepare(this);
        }
        protected function buildBackground():void{
            var _local1:MarginBackground;
            if (this.m_bgAsset){
                _local1 = new MarginBackground(this.m_bgAsset);
                this.m_cellContainer.setBackgroundDecorator(_local1);
                this.m_cellContainer.setPreferredSize(new IntDimension((CELL_WIDTH - CELL_BUFFER), CELL_HEIGHT));
                this.setPreferredSize(new IntDimension(CELL_WIDTH, CELL_HEIGHT));
            };
        }
        protected function makeLevelPanel():void{
            var _local2:DisplayObject;
            var _local3:AssetPane;
            var _local1:int;
            while (_local1 < this.m_item.level) {
                _local2 = (new (UpgradesCommonAssets.bizupsAssetDict["star"])() as DisplayObject);
                _local3 = new AssetPane(_local2);
                this.m_levelStarContainer.append(_local3);
                _local1++;
            };
        }
        protected function makePicturePanel():void{
            this.m_pictureContainer.setPreferredHeight(PIC_HEIGHT);
        }
        protected function makeStatsPanel():void{
            var _local1:ASColor = new ASColor(EmbeddedArt.blueTextColor);
            var _local2:ASColor = new ASColor(EmbeddedArt.greenTextColor);
            var _local3:ASColor = new ASColor(EmbeddedArt.redTextColor);
            this.m_statsOuterContainer.append(ASwingHelper.horizontalStrut(10));
            this.m_statsOuterContainer.append(this.m_statsInnerContainer);
            this.m_statsInnerContainer.append(ASwingHelper.verticalStrut(10));
            var _local4:JLabel = new JLabel(ZLoc.t("Dialogs", "TT_Earnings"));
            _local4.setFont(ASwingHelper.getBoldFont(11));
            _local4.setForeground(_local1);
            var _local5:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.LEFT);
            _local5.append(_local4);
            this.m_statsInnerContainer.append(_local5);
            var _local6:DisplayObject = (new EmbeddedArt.mkt_coinIcon() as DisplayObject);
            var _local7:JLabel = new JLabel(ZLoc.t("Dialogs", "NumCoins", {num:Math.ceil((this.m_item.commodityReq * Global.player.GetDooberMinimums(this.m_item, "coin")))}));
            _local7.setFont(ASwingHelper.getBoldFont(12));
            _local7.setForeground(_local2);
            var _local8:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.LEFT);
            _local8.appendAll(new AssetPane(_local6), ASwingHelper.horizontalStrut(5), _local7);
            this.m_statsInnerContainer.append(_local8);
            var _local9:JLabel = new JLabel(ZLoc.t("Dialogs", "TT_SupplyReq"));
            _local9.setFont(ASwingHelper.getBoldFont(11));
            _local9.setForeground(_local1);
            var _local10:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.LEFT);
            _local10.append(_local9);
            this.m_statsInnerContainer.append(_local10);
            var _local11:DisplayObject = (new EmbeddedArt.mkt_goodsIcon() as DisplayObject);
            var _local12:JLabel = new JLabel(ZLoc.t("Dialogs", "NumGoods", {num:this.m_item.commodityReq}));
            _local12.setFont(ASwingHelper.getBoldFont(12));
            _local12.setForeground(_local2);
            var _local13:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.LEFT);
            _local13.appendAll(new AssetPane(_local11), ASwingHelper.horizontalStrut(5), _local12);
            this.m_statsInnerContainer.append(_local13);
            this.m_statsInnerContainer.setPreferredHeight(BOX_HEIGHT);
            this.m_statsInnerContainer.setMinimumHeight(BOX_HEIGHT);
            this.m_statsInnerContainer.setMaximumHeight(BOX_HEIGHT);
        }
        protected function onPicLoad(_arg1:Event):void{
            if (((this.m_pictureLoader) && (this.m_pictureLoader.content))){
                this.m_picture = this.m_pictureLoader.content;
            };
            if ((this.m_picture is Bitmap)){
                (this.m_picture as Bitmap).smoothing = true;
            };
            this.placePicture();
        }
        protected function placePicture():void{
            var _local1:Sprite = new Sprite();
            _local1.addChild(this.m_picture);
            this.m_pictureContainer.append(new AssetPane(_local1));
            _local1.x = ((this.m_pictureContainer.width / 2) - (this.m_picture.width / 2));
            _local1.y = ((this.m_pictureContainer.height / 2) - (this.m_picture.height / 2));
            ASwingHelper.prepare(this);
        }

    }
}//package Display.UpgradesUI 
